<?php

// +----------------------------------------------------------------------
// | 产品类别栏目
// +----------------------------------------------------------------------

namespace Admins\Controller;

use Common\Controller\AdminBase;

class TryMemberController extends AdminBase {

    //商家列表
    public function index(){
        if (IS_POST) {
            $this->redirect('index', $_POST);
        }
        //查询条件
        $where = array();

        //搜索
        $search = I('get.search');
        if (!empty($search)) {
            $this->assign("search", $search);
            //添加开始时间
            $start_time = I('get.start_time');
            if (!empty($start_time)) {
                $start_time = strtotime($start_time);
                $where['create_time'] = array("EGT", $start_time);
                $this->assign('start_time', $start_time);
            }
            //添加结束时间
            $end_time = I('get.end_time');
            if (!empty($end_time)) {
                $end_time = strtotime($end_time);
                $where['create_time'] = array("ELT", $end_time);
                $this->assign('end_time', $end_time);
            }
            if ($end_time > 0 && $start_time > 0) {
                $where['create_time'] = array(array('EGT', $start_time), array('ELT', $end_time));
            }
            //搜索字段
            $searchtype = I('get.searchtype', null, 'intval');
            //搜索关键字
            $keyword = \Input::getVar(I('get.keyword'));
            if (!empty($keyword)) {
                $this->assign("searchtype", $searchtype);
                $this->assign("keyword", $keyword);
                if ($searchtype ==1) {
                    $where['mname'] = array("LIKE", "%{$keyword}%");
                }elseif ($searchtype==2) {
                    $where['mtel'] = array("LIKE", "%{$keyword}%");
                } elseif ($searchtype == 3) {
                    $where['mprovince'] = array("LIKE", "%{$keyword}%");
                }
            }
            //状态
            $status = I('get.status', 0, 'intval');
            if ($status==1) {
                $where['status'] = array("EQ", true);
            }elseif($status==2){
                $where['status']=array('EQ',false);
            }
            $this->assign('status',$status);
        }
        $model=M('TryMember');
        //信息总数
        $count = $model->where($where)->count();
        $page = $this->page($count, 30);
        $data = $model->where($where)->limit($page->firstRow . ',' . $page->listRows)->order(array("id"=>"DESC"))->select();
        $this->assign('Page', $page->show())
            ->assign('count', $count)
            ->assign('data', $data);
        $this->display();
    }


    //批量处理信息(审核,取消审核,删除)
    public function batch() {
        if (IS_POST) {
            $ids = $_POST['ids'];
            if (!$ids) {
                $this->error('没有信息被选中！');
            }
            $doAct=I('get.do');
            switch($doAct){
                case 'checkpass':
                    $data=array('status'=>true);
                    $msg='审核';
                    break;
                case 'cancelpass':
                    $data=array('status'=>false);
                    $msg='取消审核';
                    break;
            }
            foreach ($ids as $id) {
                M('TryMember')->where(array('id'=>$id))->save($data);
            }
            $this->success($msg.'成功！');
        }
    }


    //批量删除
    public function batch_delete(){
        $ids = $_POST['ids'];
        if (!$ids) {
            $this->error('没有信息被选中！');
        }
        foreach($ids as $id){
            M('TryMember')->delete($id);
        }
        $this->success('成功删除信息');
    }

}
